package common;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class Log {
	
	public static void write_log(String racine_path, String log_type, String log_message){
		
		String date_log = new SimpleDateFormat("dd/MM/yyyy à hh:mm:ss", Locale.FRANCE).format(new Date());
		File file_log = new File(racine_path+"/"+"server.log");
		if(!file_log.exists()){
			try {
				file_log.createNewFile();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		try {
			FileWriter fw = new FileWriter(file_log, true);
			BufferedWriter output = new BufferedWriter(fw);
			output.write(date_log+" - "+log_type+" : "+log_message+"\n");
			output.flush();
			output.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
}
